import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base/routes/Home.dart';
import 'package:flutter_base/routes/LoginRouter.dart';
import 'package:flutter_base/views/routeNorFount/RouteNotFound.dart';
import 'package:flutter_base/utils/route/IRouter.dart';

class BaseRouter {
  static FluroRouter _mFluroRouter = FluroRouter();

  static FluroRouter getRouter() {
    return _mFluroRouter;
  }

  static void setRouter(FluroRouter router) {
    _mFluroRouter = router;
  }

  static final List<IRouter> _mListRouter = [];

  static void registerConfigureRoutes(FluroRouter router) {
    print(router);
    if (router == null) {
      throw Exception("fluroRouter is null, please init router");
    }

    router.notFoundHandler = Handler(handlerFunc:
        (BuildContext? context, Map<String, List<String>> parameters) {
      print("页面没有注册，找不到该页面  ");
      return const RouteNotFound();
    });

    _mListRouter.clear();
    //添加模块路由
    _mListRouter.add(LoginRouter());

    _mListRouter.add(HomeRouter());

    for (var element in _mListRouter) {
      element.initFluroRouter(router);
    }
  }
}
